﻿@model DLM.Web.ViewModel.PartyPublishPageView
@{
    ViewBag.Title = "活动发布";
    Layout = "~/Views/Shared/_Master.cshtml";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-timepicker-addon.js")" type="text/javascript"></script>


<script type="text/javascript">
    function checkDate(strDate) {
        //if (strDate.length > 0) {
        //    var reg = /^(\d{2,4})-(\d{1,2})-(\d{1,2})$/g;
        //    if (!reg.test(strDate)) {
        //        return false;
        //    }
        //}
        return true;
    }

    function compareDate(startDate, endDate) {
        if (checkDate(startDate) && checkDate(endDate)) {
            //alert(startDate);
            var sdate = new Date(startDate.replace(/\-/g, "\/")); //new Date(startDate.replace(/-/g, "/")); //
            //alert(sdate);
            //alert(endDate);
            var edate = new Date(endDate.replace(/\-/g, "\/"));
            //alert(edate);
            //alert(edate - sdate);
            return edate - sdate;
        } else {
            alert("给定的日期不合法！");
        }
    }

    function checkEenDate() {
        var errorElement = $("#dateError");

        var result = compareDate($("#txtPartyDate").val(), $("#txtEndDate").val());
        //alert(result);
        if (result < 0) {
            //.next('span.field-validation-error va');
            if (errorElement) {
                errorElement.removeClass("field-validation-valid va");
                errorElement.addClass("field-validation-error");
                errorElement.empty();
                errorElement.append('<span htmlfor="txtModality" generated="true" class="" style="">结束时间不能小于开始时间</span>');
                errorElement.show();
                $("#txtLocation").attr("class", "text input-validation-error");

            }
        } else {
            $("#txtEndDate").attr("class", "text");
            errorElement.children().remove();
            errorElement.hide()
        }
    }

    $(document).ready(function () {
        $('#txtPartyDate').datetimepicker({ dateFormat: "yy-mm-dd", changeMonth: true, changeYear: true, minDate: null, maxDate: null, yearRange: 'c-50:c+20', closeText: '完成', currentText: '当前', onClose: function () { checkEenDate(); } });
        $('#txtEndDate').datetimepicker({ dateFormat: "yy-mm-dd", changeMonth: true, changeYear: true, minDate: null, maxDate: null, yearRange: 'c-50:c+20', closeText: '完成', currentText: '当前', onSelect: function (dateText, inst) { $("#txtEndDate").val(dateText);  }, onClose: function (dateText, inst) { $("#txtEndDate").val(dateText); checkEenDate(); } });
        $('#ddlProvince option:first').attr('selected', 'selected');
        $('#ddlPartyType option:first').attr('selected', 'selected');
        $("#txtModality").blur(function () {
            var errorElement = $("#modalityError");
            if ($("#txtModality").val() == "") {
                //.next('span.field-validation-error va');
                if (errorElement) {
                    errorElement.removeClass("field-validation-valid va");
                    errorElement.addClass("field-validation-error");
                    errorElement.append('<span htmlfor="txtModality" generated="true" class="" style="">请填写活动形式</span>');
                    errorElement.show();
                    $("#txtModality").attr("class", "text t_3 input-validation-error");

                } 
            } else {
                $("#txtModality").attr("class", "text t_3");
                errorElement.children().remove();
                errorElement.hide()
            }
        });

        $("#txtLocation").blur(function () {
            var errorElement = $("#locationError");
            if ($("#txtLocation").val() == "") {
                //.next('span.field-validation-error va');
                if (errorElement) {
                    errorElement.removeClass("field-validation-valid va");
                    errorElement.addClass("field-validation-error");
                    errorElement.append('<span htmlfor="txtModality" generated="true" class="" style="">请填写活动地点</span>');
                    errorElement.show();
                    $("#txtLocation").attr("class", "text t_3 input-validation-error");

                }
            } else {
                $("#txtLocation").attr("class", "text t_3");
                errorElement.children().remove();
                errorElement.hide()
            }
        });


        $("#txtEndDate").blur(function () {
      
            checkEenDate();
        });

        $("#ddlPartyType").change(function () {
            var selected = $(this).find("option:selected").text();
            if (selected == "单身男女") {
                $("#divPersonalInfo").show(1000);
                $("#divFriend").show(1000);
                $("#divOther").hide(1000);
            } else {
                //$("#divPersonalInfo").hide(1000);
                //$("#divFriend").hide(1000);
                //$("#divOther").show(1000);
                $("#divPersonalInfo").show(1000);
                $("#divFriend").show(1000);
                $("#divOther").hide(1000);
            }
            if (selected == "老乡活动") {
                $("#divLaoxiang").show(800);
                $("#lxSpan").show(500);

                $.getJSON("/Common/FindProvince", null, function (data) {
                    var ddlProvince = $("#ddlLxProvince");
                    ddlProvince.empty();
                    ddlProvince.append($('<option/>', { value: 0, text: "请选择" }));
                    $.each(data, function (index, itemData) {
                        ddlProvince.append($('<option/>', {
                            value: itemData.Value,
                            text: itemData.Text
                        }));
                    });
                });
            } else {
                $("#divLaoxiang").hide(300);
                $("#lxSpan").hide(300);
                var ddlProvince = $("#ddlLxProvince");
                ddlProvince.empty();
                ddlProvince.append($('<option/>', { value: "", text: "请选择" }));
            }

            var pid = $("#ddlPartyType").find("option:selected").val();

            $.getJSON("/Party/FindModality", { typeID: pid }, function (data) {
                var ddlModality = $("#ddlModality");
                ddlModality.empty();
                ddlModality.append($('<option/>', { value: '', text: "请选择" }));
                $.each(data, function (index, itemData) {
                    ddlModality.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
                ddlModality.append($('<option/>', { value: '', text: "其他" }));
            });

           
        });


        $("#ddlModality").change(function () {
            var mid = $("#ddlModality").find("option:selected").val();
            var text = $("#ddlModality").find("option:selected").text();
            if (text == "其他") {
                //$("#txtModality").removeAttr("disabled");
                $("#txtModality").show(500);
                $("#txtModality").focus();
                var errorElement = $("#txtModality").next('span.field-validation-error');
                if (errorElement) {
                    errorElement.children().remove(); errorElement.hide();
                    $("#ddlModality").attr("class", "sel");
                }

            } else {
                // $("#txtModality").attr("disabled", "disabled");
                $("#txtModality").hide(500);
            }
            $.getJSON("/Party/FindSupplier", { mid: mid }, function (data) {
                var ddlSupplier = $("#ddlSupplier");
                ddlSupplier.empty();
                ddlSupplier.append($('<option/>', { value: '', text: "请选择" }));
                $.each(data, function (index, itemData) {
                    ddlSupplier.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
                ddlSupplier.append($('<option/>', { value: '', text: "其他" }));
            });
        });


        $("#ddlSupplier").change(function () {
            $("#txtAddress").val($("#ddlSupplier").find("option:selected").val());
            var text = $("#ddlSupplier").find("option:selected").text();
            if (text == "其他") {
                // $("#txtLocation").removeAttr("disabled");
                $("#txtLocation").show(500);
                $("#txtLocation").focus();
                var errorElement = $("#txtLocation").next('span.field-validation-error');
                if (errorElement) {
                    errorElement.children().remove(); errorElement.hide();
                    $("#ddlSupplier").attr("class", "sel");
                }
            } else {
                // $("#txtLocation").attr("disabled", "disabled");
                $("#txtLocation").hide(500);
            }
        });

        $("#ddlLxProvince").change(function () {
            var province = $("#ddlLxProvince").find("option:selected").val();
            $.getJSON("/Common/FindCity", { province: province }, function (data) {
                var ddlCity = $("#ddlLxCity");
                ddlCity.empty();
                ddlCity.append($('<option/>', { value: '', text: "请选择" }));
                $.each(data, function (index, itemData) {
                    ddlCity.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });

        $("#edit").click(function () {
            $("#divUserInfo").append('<img src="../Content/images/loading.gif" alt="" />');
            $("#divUserInfo").load("/User/UserEdit/@Model.User.UserID")

            $("#divUserEdit").dialog(
	{
	    modal: true,
	    buttons: {
	        关闭: function () {

	            $(this).dialog("close");
	            window.location.reload(true);
	        }

	    },
	    width: 650
	}
	);

            return false;

        });

    });
</script>

<div id="divUserEdit" style="display: none;" title="会员信息编辑">

    <div id="divUserInfo">
    
    </div>
</div>


@using (Html.BeginForm("Publish", "Party", FormMethod.Post, new { enctype = "multipart/form-data" }))
{

    <div class="main">
        <div class="main_tab_2">
            <div class="main_tab_2_up">
                <ul>
                    <li class="current"><a href="#">发起活动</a></li>
                </ul>
            </div>
            <div class="main_tab_2_down">
                <div class="box">
                    <div class="tr clearfix">
    <label class="lb">
        <s></s>&nbsp;</label>
    <div class="info">
        @Html.ValidationSummary(true, "活动发布失败，请重试！")
    </div>
    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s></s>活动类型</label>
                        <div class="info">
          
                            @Html.DropDownListFor(model => model.Party.PartyType, Model.Type, "请选择", new { @class = "sel", id = "ddlPartyType" })
                            @Html.ValidationMessageFor(model => model.Party.PartyType)
                            @*        @Html.EditorFor(model => model.Modality)
                            @Html.ValidationMessageFor(model => model.Modality)*@
                            <br />
                            <span  style="color:Red;">注意：“体育活动”并非专门针对单身男女；“单身男女活动”则可以是体育类活动！</span><br />
                            
                        </div>
                    </div>
                      
                    <div id="divPersonalInfo" class="creater_info" style="display: none;">
                         <h3>
                                个人资料<a style="float:right; cursor:pointer;" id="edit">(带星号内容必填，请先完善必须的个人资料，然后再填写活动信息并发布活动！)&nbsp;编辑</a></h3>
                        @if (Model.User != null)
                        {

                            var user = Model.User;
                         
                            
                            <div class="tr clearfix">
                                <label class="lb">
                                    <s>*</s>昵称</label>
                                <div class="info">
                                    @if (!string.IsNullOrEmpty(user.AccountName))
                                    {
                                        @Html.Label(user.AccountName)
                                    }
                                </div>
                            </div>
                            
         
                            <div class="tr clearfix">
                                <label class="lb">
                                    <s>*</s>性别</label>
                                <div class="info">
                                    @switch (user.Gender.ToString())
                                    {
                                        case "False":
                                        @Html.Label("男")
                                            break;
                                        case "True":
                                        @Html.Label("女")
                                            break;
                                        default:
                                            break;
                                    }
                                </div>
                            </div>
                            <div class="tr clearfix">
                                <label class="lb">
                                    <s>*</s>出生年月</label>
                                <div class="info">
                                    @Html.Label(user.Birthday.Value.ToShortDateString())
                                </div>
                            </div>
                                   <div class="tr clearfix">
                                <label class="lb">
                                    <s>*</s>身高</label>
                                <div class="info">
                                    @Html.Label(user.Stature == null ? "" : user.Stature)厘米
                                </div>
                            </div>
                                   <div class="tr clearfix">
                                <label class="lb">
                                    <s>*</s>体重</label>
                                <div class="info">
                                    @Html.Label(user.Weight == null ? "" : user.Weight.Value.ToString())公斤
                                </div>
                            </div>
                            <div class="tr clearfix">
                                <label class="lb">
                                    <s>*</s>现居地</label>
                                <div class="info">
                                    @if (!string.IsNullOrEmpty(user.Location))
                                    {
                                        @Html.Label(user.Location)
                                    }
                                </div>
                            </div>
                            <div class="tr clearfix">
                                <label class="lb">
                                    <s>*</s>籍贯</label>
                                <div class="info">
                                    @if (!string.IsNullOrEmpty(user.NativePlace))
                                    {
                                        @Html.Label(user.NativePlace)
                                    }
                                </div>
                            </div>
                            <div class="tr clearfix">
                                <label class="lb">
                                    <s>*</s>联系方式</label>
                                <div class="info">
                                     @Html.Label(user.Phone == null ? "" : user.Phone)
                                </div>
                            </div>
           
                            <div class="tr clearfix">
                                <label class="lb">
                                    <s>*</s>收入</label>
                                <div class="info">
                                    @if (!string.IsNullOrEmpty(user.Income))
                                    {
                                        @Html.Label(user.Income == null ? "" : user.Income)
                                    }
                                </div>
                            </div>
                            <div class="tr clearfix">
                                <label class="lb">
                                    <s>*</s>工作</label>
                                <div class="info">
                                    @if (!string.IsNullOrEmpty(user.Job))
                                    {
                                        @Html.Label(user.Job == null ? "" : user.Job)
                                    }
                                </div>
                            </div>
                                    <div class="tr clearfix">
                                <label class="lb">
                                    <s>*</s>婚姻状况</label>
                                <div class="info">
                                    @if (!string.IsNullOrEmpty(user.Marriage))
                                    {
                                        @Html.Label(user.Marriage == null ? "" : user.Marriage)
                                    }
                                </div>
                            </div>
                            <div class="tr clearfix">
                                <label class="lb">
                                    <s>*</s>学历</label>
                                <div class="info">
                                    @if (!string.IsNullOrEmpty(user.Education))
                                    {
                                        @Html.Label(user.Education == null ? "" : user.Education)
                                    }
                                </div>
                            </div>
                        }
                    </div>
                    <div class="box">
                        <h3>
                            基本信息</h3>
                        <div class="tr clearfix">
                            <label class="lb">
                                <s>*</s>活动标题</label>
                            <div class="info">
                                @Html.TextBoxFor(model => model.Party.Subject, new { @class = "text t_3", maxlength = 16 })
                                @Html.ValidationMessageFor(model => model.Party.Subject, "", new { @class = "va" })<br />
                                 <span id="lxSpan" style="color:Red; display:none;">建议采用格式 例如“湖北人在上海”， “天津人在张江”，方便查看</span>
                            </div>
                        </div>
                    <h3>
                        详细信息</h3>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>活动形式</label>
                        <div class="info">
                            @Html.DropDownListFor(model => model.Party.Modality, new SelectList(Enumerable.Empty<SelectListItem>()), "请选择", new { @class = "sel", id = "ddlModality" })
                           
                           &nbsp; <input type="text" id="txtModality" name="txtModality" style="display:none;" class="text t_3", maxlength = "20" />
                            @Html.ValidationMessageFor(model => model.Party.Modality, "", new { @class = "va",id = "modalityError" })
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>具体内容</label>
                        <div class="info">
                            @Html.TextBoxFor(model => model.Party.Content, new { @class = "textarea", maxlength = 50 })
                              <span>限200字内</span>
                            @Html.ValidationMessageFor(model => model.Party.Content, "", new { @class = "va" })
                          
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>活动开始时间</label>
                        <div class="info">
                            @Html.TextBoxFor(model => model.Party.PartyDate, new { @class = "text", id = "txtPartyDate", maxlength = 18 })
                         
                            @Html.ValidationMessageFor(model => model.Party.PartyDate, "", new { @class = "va" })</div>
                    </div>
                       <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>预计结束时间</label>
                        <div class="info">
                            @Html.TextBoxFor(model => model.Party.EndDate, new { @class = "text", id = "txtEndDate", maxlength = 18 })
                          
                            @Html.ValidationMessageFor(model => model.Party.EndDate, "", new { @class = "va",id="dateError" })</div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>活动地点</label>
                        <div class="info">
                               @{ Html.RenderPartial("_CountrySelection", new DLM.Web.ViewModel.CountrySelectionPageView());}
                            <span>地点:</span>@Html.DropDownListFor(model => model.Party.Location, new SelectList(Enumerable.Empty<SelectListItem>()), "请选择", new { @class = "sel", id = "ddlSupplier", name = "ddlSupplier" })
                            &nbsp;
                            <input type="text" id="txtLocation" name="txtLocation" style="display:none;" class="text t_3", maxlength = "40"  />
                            @Html.ValidationMessageFor(model => model.Party.Location, "", new { @class = "va",id="locationError" })
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>详细地址</label>
                        <div class="info">

                            @Html.TextBoxFor(model => model.Party.Address, new { @class = "text t_3", id = "txtAddress", maxlength = 100 })
                            @Html.ValidationMessageFor(model => model.Party.Address, "", new { @class = "va" })
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>预订人数</label>
                        <div class="info">
                            @Html.TextBoxFor(model => model.Party.MemberCount, new { @class = "text t_3", maxlength = 8 })人
                            @Html.ValidationMessageFor(model => model.Party.MemberCount, "", new { @class = "va" })</div>
                    </div>
                    <div id="divLaoxiang" class="tr clearfix" style="display: none;">
                        <label class="lb">
                            <s>*</s>老乡发布范围</label>
                        <div class="info">
                    
                            @Html.DropDownList("ddlLxProvince", new SelectList(Enumerable.Empty<SelectListItem>()), "请选择", new { @class = "sel", id = "ddlLxProvince", name = "ddlLxProvince" })
                            @Html.DropDownList("ddlLxCity", new SelectList(Enumerable.Empty<SelectListItem>()), "请选择", new { @class = "sel", id = "ddlLxCity", name = "ddlLxCity" })
                         @*   @Html.DropDownList("ddlLxZone", new SelectList(Enumerable.Empty<SelectListItem>()), "请选择", new { @class = "sel", id = "ddlLxZone", name = "ddlLxZone" })*@
                            @Html.ValidationMessageFor(model => model.Party.Area)
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>预估费用</label>
                        <div class="info">
                            @Html.TextBoxFor(model => model.Party.Expense, new { @class = "text t_3", maxlength = 8 })
                            @Html.ValidationMessageFor(model => model.Party.Expense)
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>支付类型</label>
                        <div class="info">
                   
                            <div class="paid">
                                @Html.RadioButtonFor(m => m.Party.PaymentType, 1, new { @class = "radio" })男女AA<br>
                                @Html.RadioButtonFor(m => m.Party.PaymentType, 2, new { @class = "radio" })男士AA女士免费<br>
                                @Html.RadioButtonFor(m => m.Party.PaymentType, 3, new { @class = "radio" })男士人均比女士多一倍 ,m男n女总费用K，则男士负担K/(m+0.5n)元，女士负担K/(2m+n)元<br>

                              
                               
                                
                            </div>
                        </div>
                    </div>
                    <div class="tr clearfix btn">
                        <label class="lb">
                            <s></s>&nbsp;</label>
                        <div class="info">
                           
                           <div id="divFriend" style="display:none;">
                               
                                   @if (!string.IsNullOrEmpty(Model.User.Marriage) && !string.IsNullOrEmpty(Model.User.Education) && !string.IsNullOrEmpty(Model.User.Job)
                                && !string.IsNullOrEmpty(Model.User.Location) && !string.IsNullOrEmpty(Model.User.NativePlace) && !string.IsNullOrEmpty(Model.User.Income)
                                && !string.IsNullOrEmpty(Model.User.Phone) && !string.IsNullOrEmpty(Model.User.Weight.Value.ToString()) && !string.IsNullOrEmpty(Model.User.Stature) && Model.User.Photo != "none_75_75.png")
                                   { 
                                 <input type="submit" value="" id="btnPublish" class="creat" />
                            <span>工作时间1个小时内审核</span>
                                   }
                                   else
                                   {
                           
                                                               <div class="tr clearfix">
                                        <div class="attention_2">
                                            请先在个人资料区域完善您的资料，再发布活动</div>
                                    </div>
                                   }
                           </div>
                           <div id="divOther" >
                                 @if (!string.IsNullOrEmpty(Model.User.Phone))
                                 {
                                       <input type="submit" id="btnPublish" value="" class="creat" /><span>工作时间1个小时内审核</span>
                                 }
                                 else
                                 {
                                       
                                                               <div class="tr clearfix">
                                        <div class="attention_2">
                                            请先在个人资料区域完善您的资料，再发布活动</div>
                                    </div>
                                 }

                               
                            
                           </div>
                           
                           </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>

}
